package caa.struts.location.action;

import caa.struts.location.form.ManageLocationForm;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import th.com.entity.LocationEntity;
import th.com.ku.CAAService;

/**
 *
 * @author Ketsaraporn
 */
public class LocationManageAction extends DispatchAction {

   
    
    public ActionForward doAddLocation (ActionMapping mapping, ActionForm form , HttpServletRequest request, HttpServletResponse response) throws Exception {
        ManageLocationForm addLocationForm = (ManageLocationForm) form;

        String rs = CAAService.createLocation(addLocationForm.getLocationEntity());
        addLocationForm.setLocationEntity(new LocationEntity());
        
        return mapping.findForward("addlocation.success");
       
    }
    
    public ActionForward doManageLocation (ActionMapping mapping, ActionForm form , HttpServletRequest request, HttpServletResponse response) throws Exception {
        ManageLocationForm addLocationForm = (ManageLocationForm) form;

        List<LocationEntity> rs = CAAService.selectLocation(addLocationForm.getKwKeyWord());
        addLocationForm.setLocationList(new ArrayList<LocationEntity>(rs));        
        
        
        return mapping.findForward("managelocation.success");
       
    }
    
        public ActionForward doDeleteLocation (ActionMapping mapping, ActionForm form , HttpServletRequest request, HttpServletResponse response) throws Exception {
        ManageLocationForm addLocationForm = (ManageLocationForm) form;
        
        String rs = CAAService.deleteLocation(addLocationForm.getLocationId());
        
        return mapping.findForward("managelocation.do");
       
    }
}
